package com.mall.org.students.service.impl;

import java.util.List;
import com.mall.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.mall.org.students.mapper.StudentMapper;
import com.mall.org.students.domain.StudentDto;
import com.mall.org.students.service.IStudentService;

import javax.annotation.Resource;

/**
 * 学生Service业务层处理
 * 
 * @author mall
 * @date 2024-05-08
 */
@Service
public class StudentServiceImpl implements IStudentService
{
    @Resource
    private StudentMapper studentsMapper;

    /**
     * 查询学生
     * 
     * @param id 学生主键
     * @return 学生
     */
    @Override
    public StudentDto selectStudentById(Long id)
    {
        return studentsMapper.selectStudentById(id);
    }

    /**
     * 查询学生列表
     * 
     * @param studentDto 学生
     * @return 学生
     */
    @Override
    public List<StudentDto> selectStudentList(StudentDto studentDto)
    {
        return studentsMapper.selectStudentList(studentDto);
    }

    /**
     * 新增学生
     * 
     * @param studentDto 学生
     * @return 结果
     */
    @Override
    public int insertStudent(StudentDto studentDto)
    {
        studentDto.setCreateTime(DateUtils.getNowDate());
        return studentsMapper.insertStudent(studentDto);
    }

    /**
     * 修改学生
     * 
     * @param studentDto 学生
     * @return 结果
     */
    @Override
    public int updateStudent(StudentDto studentDto)
    {
        studentDto.setUpdateTime(DateUtils.getNowDate());
        return studentsMapper.updateStudent(studentDto);
    }

    /**
     * 批量删除学生
     * 
     * @param ids 需要删除的学生主键
     * @return 结果
     */
    @Override
    public int deleteStudentByIds(Long[] ids)
    {
        return studentsMapper.deleteStudentByIds(ids);
    }

    /**
     * 删除学生信息
     * 
     * @param id 学生主键
     * @return 结果
     */
    @Override
    public int deleteStudentById(Long id)
    {
        return studentsMapper.deleteStudentById(id);
    }


    @Override
    public int saveStudentInfo(StudentDto studentDto) {
        if (null != studentDto.getId()) {
            return updateStudent(studentDto);
        } else {
            return insertStudent(studentDto);
        }
    }
}
